package model

import (
	"github.com/lib/pq"
	"manager/model/entity"
)

type EbikeTypeOnOff int

const (
	EbikeTypeOn EbikeTypeOnOff = iota
	EbikeTypeOff
)

var EbikeTypeOnOffMap = map[int]EbikeTypeOnOff{
	0: EbikeTypeOn,
	1: EbikeTypeOff,
}

type EbikeTypeBaseRequest struct {
	ID int64 `json:"id" binding:"required"`
}

type EbikeTypeCreateRequest struct {
	SocketType *int `json:"socket_type" form:"socket_type" binding:"required"` // 0蓝牙  1蓝牙和4G

	Name string `json:"name" form:"name" binding:"required"`

	ParentID int64 `json:"parent_id" form:"parent_id"`

	Price *int `json:"price" form:"price" binding:"required"`

	Color pq.StringArray `json:"color"`

	Image string `json:"image" `

	Code string `json:"code" binding:"required"`

	Config string `json:"config"`

	ImagePath []string `json:"image_path" form:"image_path" binding:"required"`
}

type EbikeTypeCreateResponse struct {
	ID int64 `json:"id"`
}

type GetBikeImage struct {
	BikeId int64
	TypeId int64
	Color  string
}

type EbikeTypeUpdateRequest struct {
	ID int64 `json:"id" form:"id" binding:"required"`

	SocketType *int `json:"socket_type" form:"socket_type"`

	Name *string `json:"name" form:"name"`

	Status *int `json:"status" form:"status"`

	ParentID *int64 `json:"parent_id" form:"parent_id"`

	Price *int `json:"price" form:"price"`

	Color pq.StringArray `json:"color" form:"color"`

	Image *string `json:"image"`

	Code *string `json:"code"`

	Config *string `json:"config"`

	ImagePath pq.StringArray `json:"image_path" form:"image_path"`
}

type EbikeTypeToggleStatusRequest struct {
	ID int64 `json:"id" form:"id" binding:"required"`

	Status *int `json:"status" form:"status" binding:"required"`
}

type EbikeTypeListRequest struct {
	Index int `json:"index"`

	Size int `json:"size"`

	SocketType *int `json:"socket_type"`

	Name *string `json:"name"`

	Status *int `json:"status"`

	ID *int64 `json:"id"`

	Price *int `json:"price"`

	Code *string `json:"code"`

	Config string `json:"config"`
}

type EbikesTypeListResponse struct {
	Total int                          `json:"total"`
	Data  []*EbikeTypeListInfoResponse `json:"list"`
}

type EbikeTypeInfo struct {
	ID int64 `json:"id"`

	SocketType int `json:"socket_type"`

	Name string `json:"name"`

	Status int `json:"status"`

	ParentID int64 `json:"parent_id"`

	ParentName string `json:"parent_name"`

	Price int `json:"price"`

	Color []string `json:"color"`

	Code string `json:"code"`

	Image string `json:"image"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`

	ImagePath []string `json:"image_path"`

	Config string `json:"config"`

	ConfigUpdateAt int64 `json:"config_update_at"`
}

type EbikeTypeListInfoResponse struct {
	ID int64 `json:"id"`

	Name string `json:"name"`

	Count int64 `json:"count"`

	Status int `json:"status"`

	SocketType int `json:"socket_type"`

	Price int `json:"price"`

	Color []string `json:"color"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`

	Config string `json:"config"`

	ConfigUpdatedAt int64 `json:"config_update_at"`

	HasChild bool `json:"has_child"` // 子型号
}

type EbikeTypeDeleteRequest struct {
	ID int64 `json:"id"`
}

func EbikeTypesEntityToDto(ebikeTypes []*entity.EbikeType) []*EbikeTypeInfo {
	out := make([]*EbikeTypeInfo, 0, len(ebikeTypes))
	for _, c := range ebikeTypes {
		out = append(out, EbikeTypeEntityToDto(c))
	}
	return out
}

func EbikeTypeEntityToDto(e *entity.EbikeType) *EbikeTypeInfo {
	return &EbikeTypeInfo{

		ID: e.ID,

		SocketType: e.SocketType,

		Name: e.Name,

		Status: e.Status,

		ParentID: e.ParentID,

		Price: e.Price,

		Color: e.Color,

		Code: e.Code,

		Config: e.Config,

		Image: e.Image,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,

		ImagePath: e.ImagePath,
	}
}

type ParentEbikeTypeRequest struct {
	ID       int64  `json:"id"`
	Name     string `json:"name"`
	QueryAll *int   `json:"query_all"`
}

type ParentEbikeTypeList struct {
	ID    int64          `json:"id"`
	Name  string         `json:"name"`
	Color pq.StringArray `gorm:"column:color;type:VARCHAR(255)" json:"color"`
}

type EbikeTypeFuncConfigResponse struct {
	Config string `json:"func_config"`
}
